<template lang="html">
  <div>
    <h1>订单管理</h1>
    <div>
      <button @click="getOrder('818229994000021')">获取订单数据 818229994000021</button>
      <button @click="getOrder('818228797000122')">获取订单数据 818228797000122</button>
      <div>{{totalCount}}</div>
      <div>{{orderData.vendorOrderID}}</div>
    </div>
    <!--蓝牙打印 -->
    <div>
      <div class="BT_search">
        <a href="/pages/blueTooth/main"><button>跳转到蓝牙模块</button></a>
      </div>
    </div>
    <div>
      <button @click="printTest">打印测试</button>
    </div>
  </div>
</template>

<script>
import {$ajax} from '@/utils/request.js'
// import BL from '@/utils/lanya.js'
import pos from '@/utils/pos.js'
import moment from 'moment'
moment.locale('zh-cn')
export default {
  name: 'OrderManager',
  data () {
    return {
      orderData: '',
      totalCount: 0,
      orderSku: ''
    }
  },
  methods: {
    getOrder (orderID) {
      // let id = Number(orderID)
      // console.log(id)
      $ajax({
        url: '/v2/order/GetOrders',
        data: {
          fromDate: '2018-07-30',
          toDate: '2018-07-30',
          pageSize: 1,
          keyword: orderID
        }
      }).then(res => {
        let data = JSON.parse(res.data)
        console.log('orders', data)
        this.totalCount = data.totalCount
        this.orderData = data.data[0]
        console.log('orderData', this.orderData)
        $ajax({
          url: '/v2/order/GetOrderSkuInfo',
          data: {
            vendorOrderID: this.orderData.vendorOrderID,
            vendorID: this.orderData.vendorID
          }
        }).then(res => {
          let data = JSON.parse(res.data)
          console.log('orderSkus', data)
          this.orderSku = data
        })
      })
    },
    printTest () {
      // console.log(pos)
      pos.PrintTitle(`京西菜市`)
      pos.PrintTitle(`${moment(this.orderData.orderCreatedAt).format('YYYY-MM-DD HH:mm:ss')}`)
      pos.PrintMiddleText('--------------------------------')
      pos.PrintText(`${this.orderData.storeName}`)
      pos.PrintNameValue('实际支付: ', `￥ ${(this.orderData.actualPayPrice / 100).toFixed(2)}`)
      pos.PrintText(`品名   数量    单价         小计`)
      pos.PrintMiddleText('--------------------------------')
      this.orderSku.forEach(item => {
        pos.PrintText(`${item.skuName}`)
        pos.PPP(`${item.count}`, `${(item.salePrice / 100).toFixed(2)}`, `${(item.count * item.salePrice / 100).toFixed(2)}`)
      })
      pos.PrintMiddleText(`${this.orderData.consigneeName}`)
      pos.PrintMiddleText(`${this.orderData.consigneeMobile}`)
      pos.PrintText(`${this.orderData.consigneeAddress}`)
      pos.PrintBarcode(`${this.orderData.vendorOrderID}`)
      pos.PrintMiddleText(`${this.orderData.vendorOrderID}`)
      // pos.PrintQRcode('12345678901')
      pos.PrintMiddleText('--------------------------------')
      // 打印
      pos.PrintJumpLines(1)
      pos.DaYin()
    }
  }
}
</script>

<style lang="css">
</style>
